FROM alpine/git as clone
WORKDIR /server
# 下载datax项目
RUN git clone --progress https://gitee.com/ckx521/DataX.git

FROM maven:3.8.7-eclipse-temurin-8-alpine as build
WORKDIR /server

# maven默认仓库文件夹
RUN mkdir -p /root/.m2/repository

# 使用本地settings.xml配置
COPY settings.xml /root/.m2

# mvn本地仓库缓存，如果没有或不需要可以删除
RUN curl -o /root/.m2/repository/__mvn.tar http://127.0.0.1:8099/__mvn.tar && \
    tar -xvf /root/.m2/repository/__mvn.tar -C /root/.m2/repository && \
    mv /root/.m2/repository/__mvn/* /root/.m2/repository && \
    rm -rf /root/.m2/repository/__mvn* \

# 拷贝项目到/server下
COPY --from=clone /server/DataX /server

# 安装依赖jar包并编译
RUN chmod +x ./install.sh && \
    ./install.sh && \
    mvn --settings=/root/.m2/settings.xml -B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn \
    -Dfile.encoding=UTF-8 -Dmaven.javadoc.skip=true -DskipTests -T 12 clean package assembly:assembly

FROM rappdw/docker-java-python:openjdk1.8.0_171-python3.6.6

# 程序目录
RUN mkdir -p /opt/datax
WORKDIR /opt/datax
# 拷贝编译后的文件到/opt/datax
COPY --from=build /server/target/datax/datax /opt/datax
RUN ls
# 启动命令
CMD ["./bin/datax.py", "./job/job.json"]